using System;
using System.Data;
using System.Data.SqlClient;
using DataAccessLayer;
using EntityObjectLayer;

namespace BusinessLogicLayer
{
    public class BLClass
    {
        
        public int Saved(BEClass beclass, string Types)
        {
            SqlParameter ID = new SqlParameter("@ID", SqlDbType.Char, 10);
            SqlParameter Name = new SqlParameter("@Name", SqlDbType.NVarChar, 10);
            Name.Value = beclass.sName;
            SqlParameter Grade = new SqlParameter("@Grade", SqlDbType.Int);
            Grade.Value = beclass.iGrade;
            SqlParameter Type = new SqlParameter("@Type", SqlDbType.Char, 10);
            Type.Value = beclass.sType;

            int returnInt = 0;
            switch (Types)
            {
                case "Insert":
                    string id = "";
                    id += (DateTime.Now.Year - beclass.iGrade + 10).ToString();
                    switch (beclass.sType.Value)
                    {
                        case "KHTN":
                            id += "A";
                            break;
                        case "KHXH":
                            id += "B";
                            break;
                        case "CB":
                            id += "C";
                            break;
                    }
                    id += beclass.sName.Value;
                    ID.Value = id;
                    returnInt = Common.Execute("pr_tblClass_Insert", ID, Name, Grade, Type);
                    break;
                case "Update":
                    ID.Value = beclass.sID;
                    returnInt = Common.Execute("pr_tblClass_Update", ID, Name, Grade, Type);
                    break;
            }
            return returnInt;
        }

        public int Delete(BEClass beclass)
        {
            SqlParameter ID = new SqlParameter("@ID", SqlDbType.Char, 10);
            ID.Value = beclass.sID;
            return Common.Execute("pr_tblClass_Delete", ID);
        }

        public int UpgradeClass(string c)
        {
            SqlParameter ClassID = new SqlParameter("@Class", SqlDbType.Char, 10);
            ClassID.Value = c;
            return Common.Execute("pr_tblClass_Upgrade", ClassID);
        }


        public DataSet SelectAll()
        {
            DataTable dt=Common.GetFromDataTable("pr_tblClass_SelectAll");
            return dt.DataSet;
        }

        public DataSet getPupilByClass(string c)
        {
            SqlParameter ClassID = new SqlParameter("@Class", SqlDbType.Char, 10);
            ClassID.Value = c;
            DataTable dt=Common.GetFromDataTable("pr_tblPupil_loadClassList", ClassID);
            return dt.DataSet;
        }

        public DataSet getClassList()
        {
            DataTable dt=Common.GetFromDataTable("pr_tblClass_SelectName");
            return dt.DataSet;
        }
    }
}